<template>
  <view class="commonLim-list">
    <view
      style="margin: 10px; margin-bottom: 0"
      v-if="activityName == '生产评审'"
    >
      <uni-segmented-control
        :current="current"
        :values="subsectionlist"
        style-type="button"
        active-color="#007aff"
        @clickItem="onClickItem"
      />
    </view>
    <view class="form-content">
      <view class="form-item">
        <view>
          <text class="label">订单编号:</text>
        </view>
        <view>
          <text v-if="profile.orderCode" class="iptClass">{{
            profile.orderCode
          }}</text>
          <text class="dianwo" v-else>编号自动生成</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">客户名称:</text>
        </view>
        <view>
          <text v-if="profile.customerName" class="iptClass">{{
            profile.customerName
          }}</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">业务类型:</text>
        </view>
        <view>
          <text v-if="profile.businessTypeName" class="iptClass">{{
            profile.businessTypeName
          }}</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">预计交货日期:</text>
        </view>
        <view>
          <text v-if="profile.expectedDeliveryDate" class="iptClass">{{
            profile.expectedDeliveryDate
          }}</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">订单日期:</text>
        </view>
        <view>
          <text v-if="profile.orderDate" class="iptClass">{{
            profile.orderDate
          }}</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">销售员:</text>
        </view>
        <view>
          <text v-if="profile.salesmanName" class="iptClass">{{
            profile.salesmanName
          }}</text>
        </view>
      </view>
      <view class="form-item">
        <view>
          <text class="label">备注:</text>
        </view>
        <view>
          <text v-if="profile.remark" class="iptClass">{{
            profile.remark
          }}</text>
        </view>
      </view>
    </view>
    <view class="commonLim-listView">
      <view v-show="current == 0">
        <view v-show="orderMaterial.length">
          <view
            v-for="item in orderMaterial"
            :key="item.id"
            class="listsss_Class"
          >
            <view class="wrapBox">
              <view class="smallBox">
                <text> 物料编码: </text>
                <text> {{ item.materialCode }} </text>
              </view>
              <view class="smallBox">
                <text> 物料名称:</text>
                <text> {{ item.materialName }} </text>
              </view>
              <view class="smallBox">
                <text> 材质:</text>
                <text> {{ item.materialTypeName }} </text>
              </view>
              <view class="smallBox">
                <text> 规格型号:</text>
                <text> {{ item.specificationName }} </text>
              </view>
              <view class="smallBox">
                <text> 客户:</text>
                <text> {{ item.customerName }} </text>
              </view>
              <view class="smallBox">
                <text> 单价: </text>
                <text> {{ item.unitPrice }} </text>
              </view>
              <view class="smallBox">
                <text> 单位:</text>
                <text> {{ item.weightUnit }} </text>
              </view>
              <view class="smallBox">
                <text> 数量:</text>
                <text> {{ item.produceWeight }} </text>
              </view>
              <view class="smallBox">
                <text> 金额:</text>
                <text> {{ item.amount }} </text>
              </view>
              <view class="smallBox">
                <text> 质量要求:</text>
                <text> {{ item.qualityRequirement }} </text>
              </view>
              <view class="smallBox">
                <text> 备注:</text>
                <text> {{ item.remark }} </text>
              </view>
            </view>
          </view>
        </view>
        <up-empty mode="data" v-show="!orderMaterial.length"> </up-empty>
      </view>
      <view v-show="current == 1">
        <view v-show="manufacturingMethods.length">
          <view
            v-for="item in manufacturingMethods"
            :key="item.id"
            class="listsss_Class"
          >
            <view class="wrapBox">
              <view class="smallBox">
                <text> 生产方式:</text>
                <text> {{ item.materialName }} </text>
              </view>
              <view class="smallBox">
                <text> 材质:</text>
                <text> {{ item.materialTypeName }} </text>
              </view>
              <view class="smallBox">
                <text> 规格型号:</text>
                <text> {{ item.specificationName }} </text>
              </view>
              <view class="smallBox">
                <text> 领取量:</text>
                <text> {{ item.receiveQuantity }} </text>
              </view>
              <view class="smallBox">
                <text> 生产量: </text>
                <text> {{ item.producedQuantity }} </text>
              </view>
              <view class="smallBox">
                <text> 来源订单:</text>
                <text> {{ item.sourceOrderNo }} </text>
              </view>
              <view class="smallBox">
                <text> 客户简称:</text>
                <text> {{ item.customerAbbr }} </text>
              </view>
            </view>
          </view>
        </view>
        <up-empty mode="data" v-show="!manufacturingMethods.length"> </up-empty>
      </view>
    </view>
  </view>
</template>

<script setup>
import { searchxiangqing } from "./api.js";
import { useMemberStore } from "@/stores/modules/member";
const memberStore = useMemberStore();
const deprops = defineProps([
  "orderMaterialId",
  "MaterialdetailsId",
  "activityName",
]);
const orderMaterial = ref([]);
const manufacturingMethods = ref([]);

const profile = ref({});
const subsectionlist = ref(["订单详情", "生产方式"]);
const current = ref(0);
const handleSearch = async () => {
  const res = await searchxiangqing(
    deprops.orderMaterialId,
    deprops.workflowWorkItemId
  );
  if (res) {
    profile.value = res.order || {};
    orderMaterial.value = [res.orderMaterial] || [];
    manufacturingMethods.value = res.manufacturingMethods || [];
  } else {
    profile.value = {};
    orderMaterial.value = [];
    manufacturingMethods.value = [];
  }
};
const onClickItem = (e) => {
  current.value = e.currentIndex;
  handleSearch();
};
onLoad(async () => {
  uni.setNavigationBarTitle({
    title: `${deprops.activityName}详情`,
  });
  await Promise.all([
    memberStore.apiDictfnDetail("pick_type"),
    memberStore.salespersonListsfn(),
  ]);
  handleSearch();
});
</script>

<style lang="scss" scoped>
</style>
